<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="util" uri="/WEB-INF/kdd-util.tld" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<sec:authorize access="isAuthenticated()">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        </head>
        <body>
            <jsp:include page="../menu.jsp" />
            <jsp:include page="menu.jsp" />
            <script type="text/javascript">
                $(function() { 
                    var t = $('table#listtable')
                    $("#filter").keyup(function() {
                        $.uiTableFilter( t, this.value );
                    })
                });  
            </script>
            <div class="well notfull">
                <a href="<c:url value='/admin/subproject/add' />" class="btn btn-mini btn-primary"><spring:message code="msg.addsubproject" /></a><br /><br />
                <form>
                    <select class="projectmulti" id="projectSelector">
                        <c:forEach items="${projectList}" var="p">
                            <option value="${p.id}">${p.name}</option>
                        </c:forEach>
                    </select>
                </form>
                <input type="text" id="filter" placeholder="Filter" />
                <c:forEach items="${projectList}" var="p">
                    <div id="projectList${p.id}" class="projectlist notfullnomargin">
                        <table id="listtable" class="table table-striped table-bordered table-condensed notfull">
                            <thead>
                                <tr>
                                    <th><spring:message code="msg.subproject" /></th>
                                    <th class="creationdate"><spring:message code="msg.created" /></th>
                                    <th class="leader"><spring:message code="msg.creator" /></th>
                                    <th class="details"><spring:message code="msg.details" /></th>
                                    <th class="edit"><spring:message code="msg.edit" /></th>
                                    <th class="delete"><spring:message code="msg.delete" /></th>
                                </tr>
                            </thead>
                            <tbody>
                                <c:forEach items="${p.subProjects}" var="sp">
                                    <tr>
                                        <td>${sp.name}</td>
                                        <td><fmt:formatDate value="${sp.creationDate}" pattern="MM/dd/yyyy HH:mm"/></td>
                                        <td>${sp.creator.username}</td>
                                        <td><a class="btn btn-mini btn-info" href="<c:url value='/subproject/${sp.id}' />"><spring:message code="msg.details" /></a></td>
                                        <td><a id="editLink" class="btn btn-mini btn-info" href="<c:url value='/admin/subproject/edit/${sp.id}' />"><spring:message code="msg.edit" /></a></td>
                                        <td><a id="deleteLink" class="btn btn-mini btn-danger" href="<c:url value='/admin/subproject/delete/${sp.id}' />"><spring:message code="msg.delete" /></a></td>
                                    </tr>
                                </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </c:forEach>
                <c:if test="${not empty successString}">
                    <div class="label label-success centered notfullnomargin"><spring:message code="${successString}" /></div>
                </c:if>
                <c:if test="${not empty errorString}">
                    <div class="label label-important centered notfullnomargin"><spring:message code="${errorString}" /></div>
                </c:if>
                <script type="text/javascript">
                    $(".projectmulti").chosen();
                </script>
            </div>
            <jsp:include page="../foot.jsp" />
        </sec:authorize>